package com.example.myproject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.myproject.model.UserPermission;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;

@Mapper
@Repository
public interface UserPermissionMapper extends BaseMapper<UserPermission> {    @Select("SELECT * FROM user_permission WHERE user_id = #{userId}")
    List<UserPermission> findByUserId(@Param("userId") Long userId);

    @Insert("INSERT INTO user_permission (user_id, permission_code, permission_name, description) " +
           "VALUES (#{userId}, #{permissionCode}, #{permissionName}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertPermission(UserPermission permission);

    @Delete("DELETE FROM user_permission WHERE user_id = #{userId}")
    int deleteByUserId(@Param("userId") Long userId);

    @Update("UPDATE user_permission SET " +
            "permission_code = #{permissionCode}, " +
            "permission_name = #{permissionName}, " +
            "description = #{description} " +
            "WHERE id = #{id}")
    int updatePermission(UserPermission permission);
}